package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.ActivityCoupons;
import com.sc.nft.entity.dto.ActivityBatchIssueCouponsDTO;
import com.sc.nft.entity.dto.ActivityCouponsDTO;
import com.sc.nft.enums.CouponsListStatusEnum;
import com.sc.nft.enums.CouponsStatusEnum;
import com.sc.nft.mapper.ActivityCouponsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;


/**
 * @author liGen
 * @version 1.0
 * @date 2023/12/5 4:27 下午
 */
@Slf4j
@Repository
public class ActivityCouponsDao extends ServiceImpl<ActivityCouponsMapper, ActivityCoupons> {

    /**
     * 获取优惠券活动列表
     *
     * @param pageNo
     * @param pageSize
     * @param title    优惠券名称
     * @param status   优惠券状态 逻辑状态
     * @return
     */
    public Page<ActivityCouponsDTO> getAdminPageActivityCouponsDTO(Integer pageNo, Integer pageSize, String title, CouponsListStatusEnum status) {
        String statusCode = null;
        if (Objects.nonNull(status)){
            statusCode = status.getCode();
        }
        return baseMapper.getAdminPageActivityCouponsDTO(new Page(pageNo, pageSize), title, statusCode);
    }

    /**
     * 获取用户端优惠券活动列表
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    public Page<ActivityCouponsDTO> getMallPageActivityCouponsDTO(Integer pageNo, Integer pageSize, Long productId) {
        return baseMapper.getMallPageActivityCouponsDTO(new Page(pageNo, pageSize), productId);
    }

    /**
     * 获取用户端优惠券活动列表
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    public Page<ActivityCouponsDTO> getMallMemberActivityCouponsDTO(Integer pageNo, Integer pageSize, List<Long> activityCouponIds) {
        return baseMapper.getMallMemberActivityCouponsDTO(new Page(pageNo, pageSize), activityCouponIds);
    }

    public boolean updateSort(Long id, Integer sort) {
        UpdateWrapper<ActivityCoupons> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",id);
        wrapper.set("sort",sort);
        return update(new ActivityCoupons(),wrapper);
    }

    public boolean updateStatus(Long id, CouponsStatusEnum status) {
        UpdateWrapper<ActivityCoupons> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",id);
        wrapper.set("status",status);
        return update(new ActivityCoupons(),wrapper);
    }

    public Page<ActivityBatchIssueCouponsDTO> batchIssuePage(Integer pageNo, Integer pageSize, String title) {
        return baseMapper.batchIssuePage(new Page(pageNo, pageSize), title);
    }
}
